﻿using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Collections.Generic;
using System.Text;
using BLL.Workers;
using BLL.Workflows;
using DO.Workflows;

namespace SVC.Workflows
{
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class WorkflowDesignService : IWorkflowDesignService
    {
        public string GetWorkflow(Guid workflowID)
        {
            WorkflowDesign wfDesign = WorkflowManager.GetWorkflow(workflowID);
            return wfDesign.Save().ToString();
        }

        public string GetWorkflowByName(string workflowName)
        {
            WorkflowDesign wfDesign = WorkflowManager.GetWorkflowByName(workflowName);
            return wfDesign.Save().ToString();
        }

        public void SaveWorkflow(WorkflowDesign wfDesign)
        {
            WorkflowManager.SaveWorkflow(wfDesign);
        }

        public void PublishWorkflow(string xml)
        {
            WorkflowManager.PublishWorkflow(xml);
        }

        public List<string> ListWorkflowNames()
        {
            return WorkflowManager.ListWorkflowNames();
        }

        public void DeleteWorkflowByName(string workflowName)
        {
            WorkflowManager.DeleteWorkflowByName(workflowName);
        }

        public void DeleteWorkflow(Guid workflowID)
        {
            WorkflowManager.DeleteWorkflow(workflowID);
        }

        public void TestWorkflow(Guid workflowID)
        {
            WorkflowManualTester.RunWorkflow(workflowID);
        }
    }
}
